package com.songtech.server.entry;


import com.songtech.server.celltrack.model.CellTrack;
import com.songtech.server.celltrack.util.TransUtil;
import com.songtech.server.constant.Calculate;
import com.songtech.server.utils.CalculationUtils;
import com.songtech.server.utils.FormatDateUtils;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * Create By YINN on 2018/4/6 22:19
 * Description :
 */
public class PositionProtocal extends BaseProtocal {

    private static final long serialVersionUID = 344717650986224177L;

    //数据有效位(A/V/B)
    protected String dataValidFigure;

    //纬度标识
    protected String latitudeFlag;

    //纬度
    private Long latitude;

    //经度标识
    private String longitudeFlag;

    //经度
    private Long longitude;

    //速度
    private Long speed;

    //方位角
    private Integer direction;

    //命令日期 ddmmyy
    private Date cmdDate;

    private String equStatus;

    private String locationType;

    private Date recordTime;


    public void setAll() {

//        super.setAll(manufacturer, imei, cmd, cmdTime, cmdParam);

        if (cmdParam != null && cmdParam.length > 0) {
            setDataValidFigure(cmdParam[0]);

            //获取转化后经纬度对象
            CellTrack ct = TransUtil.GGEarthMap2BDMap(CalculationUtils.latLonParse(cmdParam[3]), CalculationUtils.latLonParse(cmdParam[1]));

            setLatitude(CalculationUtils.getLatLon(ct.getLatitude().doubleValue()));

            setLatitudeFlag(cmdParam[2]);

            setLongitude(CalculationUtils.getLatLon(ct.getLongitude().doubleValue()));

            setLongitudeFlag(cmdParam[4]);

            setSpeed((long) CalculationUtils.knotTransToMS(Double.valueOf(cmdParam[5])));
            setDirection(Integer.valueOf(cmdParam[6]));

            String dateStr = cmdParam[7];
            try {
                setCmdDate(FormatDateUtils.parseToDate(dateStr));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            setEquStatus(cmdParam[8]);

            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyy");

            setRecordTime(FormatDateUtils.dateAndTimeToDate(LocalDate.parse(dateStr, formatter), cmdTime));


//            //设置yyyy-MM-dd HH:mm:ss 时间格式
//            LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(dateStr, formatter), cmdTime);
//
//            setRecordTime(FormatDateUtils.localDateTimeToDate(localDateTime));
        }
    }

//    @Override
//    public void setAll(String manufacturer, String imei, String cmd, LocalTime cmdTime, String... cmdParam) {
//
//        super.setAll(manufacturer, imei, cmd, cmdTime, cmdParam);
//
//        if (cmdParam != null && cmdParam.length > 0) {
//            setDataValidFigure(cmdParam[0]);
//
//            setLatitude((long) (CalculationUtils.latLonParse(cmdParam[1]) * Calculate.LON_LAT_FACTOR));
//
//            setLatitudeFlag(cmdParam[2]);
//
//            setLongitude((long) (CalculationUtils.latLonParse(cmdParam[3]) * Calculate.LON_LAT_FACTOR));
//
//            setLongitudeFlag(cmdParam[4]);
//
//            setSpeed((long) (Double.valueOf(cmdParam[3]) * Calculate.SPEED_FACTOR));
//            setDirection(Integer.valueOf(cmdParam[6]));
//
//            String dateStr = cmdParam[7];
//            try {
//                setCmdDate(FormatDateUtils.parseToDate(dateStr));
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//
//            setEquStatus(cmdParam[8]);
//
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
//
//            //设置yyyy-MM-dd HH:mm:ss 时间格式
//            LocalDateTime localDateTime = LocalDateTime.of(LocalDate.parse(dateStr,formatter), cmdTime);
//
//            setRecordTime(FormatDateUtils.localDateTimeToDate(localDateTime));
//        }
//    }

    public String getDataValidFigure() {
        return dataValidFigure;
    }

    public void setDataValidFigure(String dataValidFigure) {
        this.dataValidFigure = dataValidFigure;
    }

    public String getLatitudeFlag() {
        return latitudeFlag;
    }

    public void setLatitudeFlag(String latitudeFlag) {
        this.latitudeFlag = latitudeFlag;
    }

    public Long getLatitude() {
        return latitude;
    }

    public void setLatitude(Long latitude) {
        this.latitude = latitude;
    }

    public String getLongitudeFlag() {
        return longitudeFlag;
    }

    public void setLongitudeFlag(String longitudeFlag) {
        this.longitudeFlag = longitudeFlag;
    }

    public Long getLongitude() {
        return longitude;
    }

    public void setLongitude(Long longitude) {
        this.longitude = longitude;
    }

    public Long getSpeed() {
        return speed;
    }

    public void setSpeed(Long speed) {
        this.speed = speed;
    }

    public Integer getDirection() {
        return direction;
    }

    public void setDirection(Integer direction) {
        this.direction = direction;
    }

    public Date getCmdDate() {
        return cmdDate;
    }

    public void setCmdDate(Date cmdDate) {
        this.cmdDate = cmdDate;
    }

    public String getEquStatus() {
        return equStatus;
    }

    public void setEquStatus(String equStatus) {
        this.equStatus = equStatus;
    }

    public String getLocationType() {
        return locationType;
    }

    public void setLocationType(String locationType) {
        this.locationType = locationType;
    }

    public Date getRecordTime() {
        return recordTime;
    }

    public void setRecordTime(Date recordTime) {
        this.recordTime = recordTime;
    }
}
